package com.example.myapp.chart;

import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

import com.example.myapp.R;
import com.github.mikephil.charting.charts.LineChart;

import java.util.ArrayList;
import java.util.List;

public class ChartActivity extends AppCompatActivity {

    private DynamicLineChartManager dynamicLineChartManager;
    private List<Integer> list = new ArrayList<>(); //数据集合
    private List<String> names = new ArrayList<>(); //折线名字集合
    private List<Integer> colour = new ArrayList<>();//折线颜色集合

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_chart);
        LineChart mChart1 = (LineChart) findViewById(R.id.dynamic_chart1);
        //折线名字
        names.add("温度");
        names.add("压强");
        names.add("其他");
        //折线颜色
        colour.add(Color.CYAN);
        colour.add(Color.GREEN);
        colour.add(Color.BLUE);

        dynamicLineChartManager = new DynamicLineChartManager(mChart1, names, colour);
        dynamicLineChartManager.setYAxis(100, 0, 10);
    }

    //按钮点击添加数据
    public void addEntry(View view) {
        dynamicLineChartManager.addEntry((int) (Math.random() * 100));
    }
}
